package com.evaluationSystem.util;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.evaluationSystem.config.PropertiesConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SmsSend {
    @Autowired
    private PropertiesConfig propertiesConfig;


    public String sendTSMS(String mobile, String username, String password) {

        System.out.println("=============================");
        System.out.println(propertiesConfig.getSmsUrl());
        System.out.println("=============================");
        // 请求参数
        JSONObject jsonParam = new JSONObject();
        jsonParam.put("opCode", propertiesConfig.getOpCode());
        jsonParam.put("haPhone", mobile);
        jsonParam.put("mobile", username);
        jsonParam.put("password", password);
        jsonParam.put("smsCfgId", propertiesConfig.getSmsTemplateId());

        // 发送Post请求，设置请求超时时间
        return HttpUtil.post(propertiesConfig.getSmsUrl(), jsonParam.toString(), 40000);
    }
}
